import request from '@/config/axios'
import { Sku, Spu } from '@/api/mall/product/spu'
// 提货活动 VO
export interface PickUpActivityVO {
  id: number // 主键
  name: string // 提货名称
  description: string // 提货描述
  point: number // 需要积分
  pointPickupTime:number,
  pointAndPricePickupTime:number,
  price: number // 购买价格
  provinceIds: string // 适用省份列表
  cityIds: string // 适用城市列表
  storeIds: string // 适用门店列表
  inviteNum: number // 满足的邀请人数
  memberLevel: number // 满足的用户等级
  stock: number // 剩余库存
  totalStock: number // 总库存
  startTime: Date // 提货开始时间
  endTime: Date // 提货结束时间
  status: number // 状态
  products?: ActivityProductVO[]
}

// 秒杀活动所需属性
export interface ActivityProductVO {
  skuId: number
  spuId: number
  count: number
}

// 扩展 Sku 配置
export type SkuExtension = Sku & {
  productConfig: ActivityProductVO
}

export interface SpuExtension extends Spu {
  skus: SkuExtension[] // 重写类型
}

// 提货活动 API
export const PickUpActivityApi = {
  // 查询提货活动分页
  getPickUpActivityPage: async (params: any) => {
    return await request.get({ url: `/pickup/activity/page`, params })
  },

  // 查询提货活动详情
  getPickUpActivityById: async (id: number) => {
    return await request.get({ url: `/pickup/activity/getById?id=` + id })
  },

  // 新增提货活动
  createPickUpActivity: async (data: PickUpActivityVO) => {
    return await request.post({ url: `/pickup/activity/create`, data })
  },

  // 修改提货活动
  updatePickUpActivity: async (data: PickUpActivityVO) => {
    return await request.post({ url: `/pickup/activity/update`, data })
  },

  // 修改提货活动状态
  updatePickUpActivityStatus: async (id: number, status: number) => {
    const data = {
      id,
      status
    }
    return await request.post({ url: `/pickup/activity/updateStatus`, data: data })
  },

  // 删除提货活动
  deletePickUpActivityById: async (id: number) => {
    return await request.get({ url: `/pickup/activity/delete?id=` + id })
  },

  // 导出提货活动 Excel
  exportPickUpActivity: async (params) => {
    return await request.download({ url: `/pickup/activity/export-excel`, params })
  }
}